package com.zhang.dao;

import com.zhang.pojo.Department;
import com.zhang.pojo.Employee;
import jdk.nashorn.internal.runtime.logging.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author ZhangJunqi
 * @Date 2022/2/19 -11:09
 */
@Repository
public class EmployeeDao {
    private static Map<Integer, Employee> employeesMap;
    @Autowired
    private DepartmentDao departmentDao;

    static {
        employeesMap=new HashMap<Integer, Employee> ();
        employeesMap.put (1001,new Employee (1001,"AA","AA@employee.com",1,"运维产品部",new Date ()));
        employeesMap.put (1002,new Employee (1002,"BB","BB@employee.com",0,"联锁部",new Date ()));
        employeesMap.put (1003,new Employee (1003,"CC","CC@employee.com",1,"CC部",new Date ()));
        employeesMap.put (1004,new Employee (1004,"DD","DD@employee.com",0,"ATS部",new Date ()));
    }
    public Collection<Employee> getAllEmployee(){
        return employeesMap.values ();
    }
    private static Integer initId=1005;
    public void saveEmployee(Employee employee){
        if(employee.getId ()==null){
            employee.setId (initId++);
        }
        //employee.setEmployeeName (departmentDao.getDepartmentByName (employee.getDepartmentName ()));
        employeesMap.put (employee.getId (),employee);
    }

    public Employee getEmployeeById(Integer id){
        return employeesMap.get (id);
    }

    public Integer deleteEmployeeById(Integer id){
        try {
            employeesMap.remove (id);
            return 1;
        }catch (Exception e){
            System.out.println(e);
            return 0;
        }

    }
}
